package personal.zq.generator.sys.service.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import lombok.SneakyThrows;
import personal.zq.generator.sys.common.utils.BeanUtils;

/**
 * 分页工具类
 *
 * @author zhangqing
 * @version 1.0
 * @date 2022/6/27
 */
public class PageUtils {
    @SneakyThrows
    public static <T> IPage<T> convertPage(IPage iPage, Class<T> clz) {
        IPage<T> resp = new Page();
        List<T> list = BeanUtils.copyArray(iPage.getRecords(), clz);
        resp.setRecords(list);
        resp.setCurrent(iPage.getCurrent());
        resp.setSize(iPage.getSize());
        resp.setTotal(iPage.getTotal());
        resp.setPages(iPage.getPages());
        return resp;
    }
}
